#!/usr/bin/python
# -*- coding: utf8 -*-

import logging

from pymylib.lib.base import *
from pymylib.model import Session, BiblioType, Category, User, category_table
from sqlalchemy import select, text

log = logging.getLogger(__name__)

class SetupController(BaseController):

    def index(self):
        """Типы"""
        biblio_type = BiblioType()
        biblio_type.name = 'Книга'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'Журнал'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'CD (Audio)'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'CD (PC)'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'CD (Video)'
        Session.save(biblio_type)
        Session.commit()

        biblio_type = BiblioType()
        biblio_type.name = 'DVD (Video)'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'DVD (PC)'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'DVD (Audio)'
        Session.save(biblio_type)
        Session.commit()
        
        biblio_type = BiblioType()
        biblio_type.name = 'Видео кассета'
        Session.save(biblio_type)
        Session.commit()

        """Категории"""
        category = Category()
        category.id = -1
        category.name = '.::БЕЗ ЖАНРА::.'
        Session.save(category)
        Session.commit()
                
        category = Category()
        category.name = 'Художественная литература'
        Session.save(category)
        Session.commit()
        
        category = Category()
        category.name = 'Компьютерная литература'
        Session.save(category)
        Session.commit()
        
        category = Category()
        category.name = 'Христианска литература'
        Session.save(category)
        Session.commit()

        category = Category()
        category.name = 'Фэнтэзи'
        Session.save(category)
        Session.commit()
        
        category = Category()
        category.name = 'Мюзикл'
        Session.save(category)
        Session.commit()
                
        category = Category()
        category.name = 'Техническая литература'
        Session.save(category)
        Session.commit()
                
        category = Category()
        category.name = 'Разное по Linux'
        Session.save(category)
        Session.commit()
        
        category = Category()
        category.name = 'Концерты'
        Session.save(category)
        Session.commit()
        
        category = Category()
        category.name = 'Христианская музыка'
        Session.save(category)
        Session.commit()

        """User"""
        user = User()
        user.fio = 'Администратор системы'
        user.email = 'admin@pymylib.ru'
        user.user_name = 'admin'
        user.permitions = 15
        Session.save(user)
        Session.commit()
        
        return 'Необходимые данные залиты!'
